var form, $,areaData;
layui.use(['form','layer','upload','laydate'],function(){
    form = layui.form;
    $ = layui.jquery;
    var layer = parent.layer === undefined ? layui.layer : top.layer,
        upload = layui.upload,
        laydate = layui.laydate;
    form.on("submit(changeUser)",function(data){
        var roleIds = [];
         $("input:checkbox[name='roleId']:checked").each(function(i){
                roleIds.push($(this).val());
         });
		var index = layer.msg('提交中，请稍候',{icon: 16,time:false,shade:0.8});
        $.post("/user/grant",{
        	roleIds:roleIds,
        	userId:$("#userId").val()
        },function(res){
	       	 if(res.code==0){
	       		 layer.msg(res.msg);
                 var index = parent.layer.getFrameIndex(window.name);
                 parent.layer.close(index);
	       	 }else{
	       		 layer.msg(res.msg);
	       	 }
        })
        setTimeout(function(){
            top.layer.close(index);
            layer.closeAll("iframe");
        },2000);
        return false;
    })
});